
import { Inject, Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from '../entity';
import { Repository, EntityRepository } from 'typeorm';

@Injectable()
export class UserInfoMiddleware implements NestMiddleware {
  constructor(

    @InjectRepository(User)
    private readonly userRepository: Repository<User>

    ) { }
  use(req: Request, res: Response, next: () => void) {
    const authorization = req.headers.authorization;
    console.log(authorization)
    this.userRepository.findOne(authorization)
      .then(user => {
        console.log(user)
        next();
      }).catch(error => { next(); });
  }
}
